package com.appmagna.sleepaidfan;

import android.app.Application;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.flurry.android.FlurryAgent;
import io.fabric.sdk.android.services.settings.SettingsJsonConstants;

public class SleepAidFanApplication extends Application {
    static volatile SleepAidFanApplication application = null;
    Boolean m_fIsUnknownMode = false;
    float m_fScaleX;
    float m_fScaleY;
    int nDisplaySize;
    int nDisplaySize1;

    public void onCreate() {
        super.onCreate();
        new FlurryAgent.Builder().withLogEnabled(true).build(this, getString(R.string.flurry_api_key));
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp((Application) this);
        AppEventsLogger.newLogger(this).logEvent("App Launched");
    }

    public SleepAidFanApplication() {
        application = this;
    }

    public static SleepAidFanApplication getInstance() {
        return application;
    }

    public void setDisplayMode(int nWidth, int nHeight, float density) {
        if (nWidth > nHeight) {
            int tmp = nWidth;
            nWidth = nHeight;
            nHeight = tmp;
        }
        float rate = ((float) nHeight) / ((float) nWidth);
        this.m_fIsUnknownMode = true;
        if (nWidth == 480 || nWidth == 1344 || nWidth == 1440 || nHeight == 2560 || nHeight == 2392) {
            if (nHeight == 854) {
                this.nDisplaySize = 482;
            } else {
                this.nDisplaySize = 480;
            }
        } else if (nWidth == 540 || nWidth == 1080) {
            if (((double) rate) > 1.77d) {
                this.nDisplaySize = 540;
            } else {
                this.nDisplaySize = 541;
            }
        } else if (nWidth == 600 || nWidth == 1200) {
            this.nDisplaySize = SettingsJsonConstants.ANALYTICS_FLUSH_INTERVAL_SECS_DEFAULT;
        } else if (nWidth == 640) {
            this.nDisplaySize = 640;
        } else if (nWidth == 720) {
            this.nDisplaySize = 720;
        } else if (nWidth != 800 && nWidth != 1600) {
            if (((double) rate) <= 1.78d) {
                this.nDisplaySize = 482;
            }
            if (((double) rate) <= 1.71d) {
                this.nDisplaySize = SettingsJsonConstants.ANALYTICS_FLUSH_INTERVAL_SECS_DEFAULT;
            }
            if (((double) rate) <= 1.67d) {
                this.nDisplaySize = 480;
            }
            if (((double) rate) <= 1.65d) {
                this.nDisplaySize = 720;
            }
            if (((double) rate) <= 1.64d) {
                this.nDisplaySize = 801;
            }
            if (((double) rate) <= 1.52d) {
                this.nDisplaySize = 640;
            }
            this.m_fIsUnknownMode = true;
        } else if (nHeight < 1224) {
            this.nDisplaySize = 802;
        } else if (nWidth == 800) {
            this.nDisplaySize = 800;
        } else {
            this.nDisplaySize = 801;
        }
        this.nDisplaySize1 = this.nDisplaySize / 10;
        if (this.nDisplaySize == 640) {
            this.m_fScaleX = (((float) nWidth) / 320.0f) / density;
            this.m_fScaleY = (((float) nHeight) / 480.0f) / density;
        } else if (this.nDisplaySize == 480) {
            this.m_fScaleX = (((float) nWidth) / 320.0f) / density;
            this.m_fScaleY = (((float) nHeight) / 533.0f) / density;
        } else if (this.nDisplaySize == 482) {
            this.m_fScaleX = (((float) nWidth) / 320.0f) / density;
            this.m_fScaleY = (((float) nHeight) / 569.0f) / density;
        } else if (this.nDisplaySize == 600) {
            this.m_fScaleX = (((float) nWidth) / 320.0f) / density;
            this.m_fScaleY = (((float) nHeight) / 533.0f) / density;
        } else if (this.nDisplaySize1 == 54) {
            this.m_fScaleX = (((float) nWidth) / 360.0f) / density;
            this.m_fScaleY = (((float) nHeight) / 592.0f) / density;
        } else if (this.nDisplaySize == 720) {
            this.m_fScaleX = (((float) nWidth) / 360.0f) / density;
            this.m_fScaleY = (((float) nHeight) / 592.0f) / density;
        } else if (this.nDisplaySize1 == 80) {
            this.m_fScaleX = (((float) nWidth) / 400.0f) / density;
            this.m_fScaleY = (((float) nHeight) / 616.0f) / density;
        }
    }
}
